﻿using System;
using Enyim.Caching;
using Enyim.Caching.Memcached;

namespace Pansoft.HIME.CacheManager
{
    public class MemCachedHelper
    {
        
        #region 单件实例

        private static readonly Lazy<MemCachedHelper> _Instance = new Lazy<MemCachedHelper>(() => new MemCachedHelper());

        /// <summary> 获得一个本类型的单件实例.
        /// </summary>
        /// <value>The instance.</value>
        public static MemCachedHelper Instance
        {
            get { return _Instance.Value; }
        }
        
        private MemCachedHelper() { }

        #endregion
			

        public void Store(string key,object value)
        {
            using (var mc = new MemcachedClient())
            {
                mc.Store(StoreMode.Set, key, value);
            }
        }

        public object Fetch<T>(string key)
        {
            using (var mc = new MemcachedClient())
            {
                return mc.Get<T>(key);
            }
        }
    }
}